﻿using System;
using System.Timers;

namespace BaseSyntax.Event.DefineEvent
{
	// 先定义委托类型
	public delegate void ListenerDel(string msg);
	public class Connection
	{
		public event ListenerDel listener;
		private Timer timer;

		public Connection()
		{
			timer = new Timer(1000);
			timer.Elapsed += new ElapsedEventHandler(TimerHandle);
		}
		
		public void Connect()
		{
			timer.Start();
			// listener.
		}
		
		Random ran = new Random();
		public void TimerHandle(object o1, ElapsedEventArgs e)
		{
			Console.WriteLine("timer Handle");
			listener?.Invoke(ran.Next(1000).ToString());
		}
	}
}